class Solution {
public:
    vector<int> singleNumber(vector<int>& nums) {
        int tmp = 0;
        for (auto x : nums)
            tmp ^= x;
        
        int index = 1;
        while ((tmp & index) == 0)
            index <<= 1;

        int ret1 = 0, ret2 = 0;
        for (auto x : nums)
        {
            if (x & index) ret1 ^= x;
            else ret2 ^= x;
        }

        return {ret1, ret2};
    }
};